#ifndef _QUADTREE_H
#define _QUADTREE_H
#include "objects.h"

typedef struct mySquare
{
	int x,y,length;
};

typedef struct myRect
{
	int x,y,w,h;
};

class QuadNode
{
public:
	QuadNode();
	~QuadNode();
	mySquare * sqr;

	QuadNode * LT;
	QuadNode * RT;
	QuadNode * LB;
	QuadNode * RB;

	int index,lvl;
};

class QuadTree
{
public:

	int lastRes,res[200],result,type;
	QuadNode * Root;
	QuadTree(int);
	~QuadTree();

	void Find(float,float,int,int);
	void Add(CObjects *obj,int i);
	void AddPixel(QuadNode * node,int,int,int);
	
	bool existInResult(int);

	bool inRect(int,int,myRect*);
	bool CutX(myRect*,myRect*);
	void Check(int,int,int,int);
	void CheckCollision(CObjects *Obj);
	void RenderScreen(int,int,LPDIRECT3DDEVICE9 d3ddv,int t);
	void Search(QuadNode *node,myRect * Sqr);
	int Del(int x,int y,int w,int h);
	void DelPixel(QuadNode*,myRect*);
};
#endif